$(function () {
    var addressList =""
    $.ajax({
        url: '/address/queryAddress',
        type: "GET",
        dataType: "json",
        success: function (res) {
            if(res.error &&res.error==400){
                mui.toast("请先登录账号")
                setTimeout(() => {
                    location.href="login.html"
                }, 500);
            }
            addressList =res
            console.log(res)
            var html = template('templates', {
                msg2: res
            })

            $("#OA_task_1").html(html)
        }
    })

    $("#OA_task_1").on('tap', '.addressDel', function () {
        console.log($(this).parent().parent().attr("data-id"))
        console.log(this.parentNode.parentNode.getAttribute("data-id"))
        var delId = $(this).parents(".addLi").attr("data-id")
        var domli =this.parentNode.parentNode
        mui.confirm("确认删除？", function (mes) {
            if (mes.index == 1) {
                $.ajax({
                    url: '/address/deleteAddress',
                    type: "POST",
                    data: {
                        id: delId
                    },
                    success: function (res) {
                        if (res.success) {
                            mui.toast("删除成功")
                            setTimeout(() => {
                                location.reload()
                            }, 1000)
                        }
                    }
                })
            }else{
                mui.swipeoutClose(domli)
            }
        })
    })
   
    $("#OA_task_1").on('tap','.addressEdit',function(){
        console.log($(this).parent().parent().attr("data-id"))
        console.log($(this))
        var Oid = $(this).parent().parent().attr("data-id")
        console.log(addressList)
        for(var j=0;j<addressList.length;j++){
            if(addressList[j].id==Oid){
                localStorage.setItem("Oedit",JSON.stringify(addressList[j]))
                location.href="addAddress.html?datas=1"
            }
        }
        // var mylist = localStorage.setItem()
    })
   
})